package com.pzitsoft.videoteca.web;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.pzitsoft.videoteca.domain.Actor;
import com.pzitsoft.videoteca.domain.Director;
import com.pzitsoft.videoteca.domain.Genero;
import com.pzitsoft.videoteca.domain.Idioma;
import com.pzitsoft.videoteca.domain.Pais;
import com.pzitsoft.videoteca.domain.Pelicula;
import com.pzitsoft.videoteca.domain.Tipo;
import com.pzitsoft.videoteca.service.PersonaManager;
import com.pzitsoft.videoteca.service.VideoManager;

/**
 * Handles requests for the application home page.
 */
@Controller
public class HomeController {
	
	private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
	
	@Autowired
	private VideoManager videoManager;
	@Autowired
	private PersonaManager personaManager;
	/**
	 * Simply selects the home view to render by returning its name.
	 */
	@RequestMapping(value = "/", method = RequestMethod.GET)
	public ModelAndView home(Locale locale) {
		logger.info("Bienvenido! El cliente local es {}.", locale);
		Actor a=new Actor("Jim", "Carrey", null);
		Director d=new Director("Chuck", "Russell", null);
//		personaManager.addDirector(d);
		d.setId(2);
//		personaManager.addActor(a);
		a.setId(1);
//		Genero g=new Genero(1, "Fantasia");
//		Set<Genero> generos=new HashSet<Genero>();
//		generos.add(g);
//		
//		
//		Idioma i=new Idioma(1, "Ingles");
//		Set<Idioma> idiomas=new HashSet<Idioma>();
//		idiomas.add(i);
//		
//		Set<Actor> actores=new HashSet<Actor>();
//		actores.add(a);
//		
//		Pelicula p=new Pelicula("una sinopsis", "110", "La Mascara", generos, Tipo.REAL, new Timestamp(0), idiomas, new Pais(1, "Estados Unidos"), true, true);
//		p.setTituloOriginal("The Mask");
//		p.setDirector(d);
//		p.setActores(actores);
//		videoManager.addPelicula(p);
//		List<Pelicula> videos=videoManager.getAllPeliculas();
//		videos.get(0);
		Date date = new Date();
		DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, 0, locale);
		String formattedDate = dateFormat.format(date);
		Map<String, Object> myModel = new HashMap<String, Object>();
		myModel.put("serverTime", formattedDate );
		
		return new ModelAndView("home", "model", myModel);
	}
	
}
